// Test for the db::escape function
// Copyright 2006 (C) Ralph Thomas

#include <util/db.h>
#include <tests/testCore.h>

class testDbEscape : public test::basic {
	static bool dotest( const std::string& input, const std::string& expected, std::string& result ) {
		if( util::db::escape( input ) != expected ) {
			result = "FAILED ON: " + input;
			return false;
		}
		return true;
	}
  public:
	const char* performTest() {
		std::string result;
		if( !dotest( "hello", "hello", result ) )
			return result.c_str();
		if( !dotest( "o'hare", "o''hare", result ) )
			return result.c_str();
		if( !dotest( "'quoted'", "''quoted''", result ) )
			return result.c_str();
		if( !dotest( "q''p", "q''''p", result ) )
			return result.c_str();
		return 0;
	}
	const char* getTestName() {
		return "Test exercising util::db::escape function";
	}
};

void test::runnerSingleton::registerTests() {
	adoptTest( new testDbEscape() );
}
